// 后端返回的频道结构
export type Channel = {
  id: number
  name: string
}

// 频道 State 注解
export type ChannelState = {
  list: Channel[]
  active: number
}

// 初始化状态应用注解
export const initState: ChannelState = {
  list: [],
  active: 0,
}

// 频道 Action 注解
export type ChannelAction =
  | { type: 'channel/saveList'; payload: Channel[] }
  | { type: 'channel/setActive'; payload: number }

export default function channelReducer(state = initState, action: ChannelAction) {
  switch (action.type) {
    case 'channel/saveList':
      return { ...state, list: action.payload }
    case 'channel/setActive':
      return { ...state, active: action.payload }
    default:
      return state
  }
}
